package cn.lingyangwl.agile.infra.weixin.mp.handler.scanbiz;

import cn.lingyangwl.agile.infra.common.QrCodeSceneEnum;
import cn.lingyangwl.agile.infra.common.ScanScene;
import cn.lingyangwl.agile.msg.push.api.constatnts.ChannelTypeEnum;
import cn.lingyangwl.agile.msg.push.api.constatnts.NoticeCodeEnum;
import cn.lingyangwl.agile.msg.push.api.model.content.MsgParam;
import cn.lingyangwl.agile.msg.push.api.utils.MsgPushUtils;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import org.springframework.stereotype.Component;

/**
 * @author shenguangyang
 */
@Slf4j
@Component
public class WxOpenIdGetHandler extends BaseWxScanEventHandler {
    @Override
    protected void processBiz(WxMpXmlMessage message, ScanScene scanScene) {
        JSONObject params = scanScene.getParams();
        String loginId = params.getString(ScanScene.LOGIN_ID);
        String userId = params.getString(ScanScene.USER_ID);

        MsgParam content = new MsgParam();
        content.setCode(NoticeCodeEnum.BIZ_SITE_PUSH.getCode());
        content.setBizType(scanScene.getSceneCode()).setLoginId(loginId);
        content.addMsgField("data", message.getFromUser());

        MsgPushUtils.push(ChannelTypeEnum.PC, content, userId);
    }

    @Override
    protected QrCodeSceneEnum scene() {
        return QrCodeSceneEnum.GET_OPENID;
    }
}
